﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;

namespace Crayons
{
    public class Sprite
    {
        public struct Module
        {
            Int32 Identifier;
            String UniqueKey;
            Rectangle DataRect;
            Byte[] CacheARGB;
        }

        public struct Frame
        {
            Module[] Modules;
            Point[] Position;
            UInt32[] Flags;
            Byte[] CacheARGB;
        }

        public struct Animation
        {
            Frame[] Frames;
            Point[] Position;
            UInt32[] Times;
        }


        protected String[] m_imgPath;
        protected String[] m_palletePath;
        protected Module[] m_modules;
        protected Frame[] m_frames;
        protected Animation[] m_animations;

        protected Sprite()
        {
            //TO DO
        }

        public static Sprite CreateSprite(Stream dataStream)
        {
            Sprite sprite = new Sprite();
            if (!sprite.LoadBinarySprite())
            {
                if (!sprite.LoadJsonSprite(dataStream))
                    return null;
            }
            return sprite;
        }

        protected bool LoadJsonSprite(Stream dataStream)
        {
            StreamReader reader = new StreamReader(dataStream);
            String json = reader.ReadToEnd();
            ArrayList arrLs = fastJSON.JSON.Instance.Parse(json) as ArrayList;
            return false;
        }

        protected bool LoadBinarySprite()
        {
            //TO DO
            return false;
        }

        public void DrawModule()
        {

        }

        public void DrawFrame()
        {

        }

        public void DrawAnimation()
        {

        }
    }
}
